package com.workpaper.app.navigation.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.part.ViewPart;

import com.workpaper.app.cache.resource.ViewInfoCache;
import com.workpaper.app.consts.navigation.NavigationViewConsts;
import com.workpaper.app.navigation.view.listener.NavigationMouseListener;

public class NavigationView extends ViewPart{
	
	private Tree navigatTree;
	public NavigationView() {
	}

	@Override
	public void createPartControl(Composite parent) {
		
		parent.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		navigatTree = new Tree(parent, SWT.BUTTON5);
		navigatTree.setLinesVisible(true);
		navigatTree.setHeaderVisible(true);
		navigatTree.setRedraw(false);
		
		createNavigationMenus();
		//设置完成后进行重绘
		navigatTree.setRedraw(true);
		
	}
	

	/**
	 * 创建功能导航
	 */
	public void createNavigationMenus() {
		String[] model = new String[] {ViewInfoCache.get(NavigationViewConsts.modelPlan), 
				ViewInfoCache.get(NavigationViewConsts.modelWork), ViewInfoCache.get(NavigationViewConsts.modelPerformance)};
		String[][] menu = {
				{ViewInfoCache.get(NavigationViewConsts.menuPlanManage), ViewInfoCache.get(NavigationViewConsts.menuPlanDo), 
					ViewInfoCache.get(NavigationViewConsts.menuPlanStatistic)}, 
				{ViewInfoCache.get(NavigationViewConsts.menuWorkpaperDay), ViewInfoCache.get(NavigationViewConsts.menuWorkpaperWeek)}, 
				{ViewInfoCache.get(NavigationViewConsts.menuPerformanceAppraisalPersonal), ViewInfoCache.get(NavigationViewConsts.menuPerformanceAppraisalTeam)}} ;
		for (int i = 0; i < model.length; i++) {
			TreeItem funBtn = new TreeItem(navigatTree, SWT.BORDER);
			funBtn.setText(model[i]);
			for (int j = 0; j < menu[i].length; j++) {
				TreeItem sonBtn = new TreeItem(funBtn, SWT.BORDER);
				sonBtn.setText(menu[i][j]);
				sonBtn.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
			}
		}
		navigatTree.addMouseListener(new NavigationMouseListener(navigatTree));
	}
	
	

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}

}
